//
//  YZMSetBorderAndCorner.m
//  YZMicroStock
//
//  Created by apple on 17/8/1.
//  Copyright © 2017年 cqjr. All rights reserved.
//

#import "YZMSetBorderAndCornerRadius.h"

@implementation YZMSetBorderAndCornerRadius

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (void)setView:(UIView *)iv borderWidth:(CGFloat)borderWidth borderColor:(UIColor *)borderColor cornerRadius:(CGFloat)cornerRadius{
    if (iv) {
        [iv.layer setBorderWidth:borderWidth];
        [iv.layer setBorderColor:borderColor.CGColor];
        [iv.layer setCornerRadius:cornerRadius];
        if ([iv isKindOfClass:[UIImageView class]]) {
            iv.layer.masksToBounds = YES;
        }
    }
}

+ (void)addLineViewWithParentView:(id)iv{
    if (iv != nil) {
        UIView *viewLine = [[UIView alloc] init];
        viewLine.backgroundColor = [YZMAppStyle colorForLine];
        [iv addSubview:viewLine];
        [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(iv);
            make.height.equalTo(@1);
        }];
    }
}

+ (void)addVerLineViewWithView:(id)iv width:(CGFloat)width color:(UIColor *)color{
    if (iv != nil) {
        UIView *viewLine = [[UIView alloc] init];
        if (color) {
            viewLine.backgroundColor = color;
        }else{
            viewLine.backgroundColor = [YZMAppStyle colorForLine];
        }
        [iv addSubview:viewLine];
        [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.right.equalTo(iv);
            if (width) {
                make.width.mas_equalTo(width);
            }else{
                make.width.equalTo(@1);
            }
            
        }];
    }
}

+ (void)addVerLineViewWithView:(UIView *)iv width:(CGFloat)width color:(UIColor *)color top:(CGFloat)top bottom:(CGFloat)bottom{
    if (iv != nil) {
        UIView *viewLine = [[UIView alloc] init];
        if (color) {
            viewLine.backgroundColor = color;
        }else{
            viewLine.backgroundColor = [YZMAppStyle colorForLine];
        }
        [iv addSubview:viewLine];
        [viewLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(iv);
            if (width) {
                make.width.mas_equalTo(width);
            }else{
                make.width.equalTo(@1);
            }
            if (top) {
                make.top.equalTo(iv.mas_top).offset(top);
            }else{
                make.top.equalTo(iv);
            }
            if (bottom) {
                make.bottom.equalTo(iv.mas_bottom).offset(bottom);
            }else{
                make.bottom.equalTo(iv);
            }
            
        }];
    }
}

@end
